<?php
session_start();

//如果是post请求才执行代码
//php如何判断是否post请求
if($_SERVER['REQUEST_METHOD']=='POST'){
	
//获取前端表单提交的用户名
$username = $_POST['username'];
$password = $_POST['password'];

//根据用户提交的账号密码 从数据库获取账号密码
if($username == "admin"&& $password == "123456"){
	//设置cookie，记录用户已经登陆
	$_SESSION['username'] = $username;
	die ("登陆成功");
}else{
	die ("登录失败");
}

}

if(isset($_SESSION['username'])){
	header('location:add.php');
}
?>

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title></title>
	<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
	
	<!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
	
	<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
	<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

	<style>
		.login-box{
			margin-top:200px;
			padding:50px;
			border-radius: 20px;
			position: relative;
		}
		/* 让每个输入框之间有间距  做法：给login-box的每个子元素div设置外边距 */
		.login-box>div{
			margin-bottom:20px;
		}
		
		.login-box>.into{
			position: absolute;
			background-color: white;
			width:100%;
			height:100%;
			z-index: -1;
			top:-5px;
			left:-5px;
			opacity: 0.7;
			border-radius: 20px;
		}
		
		body{
			background: url(imgs/1.jpg) no-repeat;
			
			/* 让图片铺满整个页面 */
			background-size: cover;    
		}
		html{
			height: 100%;
			/* 隐藏超出部分，去除滚动条 */
			overflow: hidden;
		}
	</style>
</head>
<body>
	
	<div class="row">
		<form action="" method="post">
	  <!-- col-md-offset-4 表示向右偏移4个格子（前面空4格） -->
	  <div class="col-md-4 col-md-offset-4 login-box">
		  <div class="into"></div>
		  <div class="input-group input-group-lg">
		    <span class="input-group-addon">账号</span>
		    <input type="text" name="username" class="form-control" placeholder="用户名">
		  </div>
		  <div class="input-group input-group-lg">
		    <span class="input-group-addon">密码</span>
		    <input type="text" name="password" class="form-control" placeholder="密码">
		  </div>
		  <div>
		  	<button type="submit" class="form-control btn btn-primary">登录</button>
		  </div>
	  </form>
	  </div>
	</div>

</body>
</html>
